package cn.kgc.tangcco.controller;

import cn.kgc.tangcco.pojo.Idiom;
import cn.kgc.tangcco.service.IdiomService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutionException;

/**
 * @author 李昊哲
 * @Description
 * @create 2021/1/27 11:59
 */
@RestController
@RequestMapping(value = "/idiom")
public class IdiomController {
    private final IdiomService idiomService;
    private static ObjectMapper objectMapper = new ObjectMapper();

    public IdiomController(IdiomService idiomService) {
        this.idiomService = idiomService;
    }

    @GetMapping(value = "/selectById/{id}")
    public Idiom selectById(@PathVariable(name = "id") Integer id) throws ExecutionException, InterruptedException, JsonProcessingException {
//        for (int i = 0; i < 10; i++) {
//            System.out.println(objectMapper.writeValueAsString(idiomService.selectById(ThreadLocalRandom.current().nextInt(20, 100)).get()));
//        }
        return idiomService.selectById(id).get();
    }
}
